<template>
  <s-layout title="新首页" navbar="custom" tabbar="/pages/index/cueIndex">
    <view class="home-container" :style="{ backgroundImage: `url(${backgroundImage})` }">
      
      <!-- 顶部导航栏 -->
      <view class="center-nav">
        <view class="top-nav">
          <view class="nav-item-wrapper">
            <view class="nav-item" :class="{ active: currentTab === 'handmade' }" @click="handleTabChange('handmade')">
              <text>手工杆</text>
            </view>
          </view>
          <view class="nav-item-wrapper">
            <view class="nav-item" :class="{ active: currentTab === 'finished' }" @click="handleTabChange('finished')">
              <text>成品杆</text>
            </view>
          </view>
          <view class="nav-item-wrapper">
            <view class="nav-item" :class="{ active: currentTab === 'culture' }" @click="handleTabChange('culture')">
              <text>企业文化</text>
            </view>
          </view>
        </view>
      </view>

      <!-- 内容区域 -->
      <view class="content-container">
        <!-- 成品杆列表 -->
        <view v-if="currentTab === 'finished'" class="finished-cues-section">
          <view class="cues-grid">
            <view class="cue-item" v-for="(cue, index) in finishedCues" :key="index" @click="handleCueClick(cue.id)">
              <image :src="cue.imageUrl" class="cue-image" mode="widthFix"></image>
              <text class="cue-name">{{ cue.name }}</text>
            </view>
          </view>

          <!-- 新增：查看更多按钮 -->
          <view class="load-more-btn" @click="handleLoadMore">
            <text class="btn-text">查看更多</text>
          </view>
        </view>

        <view v-else-if="currentTab === 'culture'" class="other-content">
          <view class="placeholder-text">企业文化内容展示区域</view>
        </view>
      </view>

      <!-- 底部固定按钮 -->
      <view v-if="currentTab === 'handmade'" class="fixed-bottom-btn">
        <view class="custom-btn" @click="handleBookTest" 
              :style="{ backgroundImage: `url(https://zero-one01.oss-cn-shenzhen.aliyuncs.com/app/yysd.png)`, 
                       backgroundSize: 'contain', 
                       backgroundRepeat: 'no-repeat', 
                       backgroundPosition: 'center' }">
        </view>
        <view class="custom-btn" @click="handleSelectMatch"
              :style="{ backgroundImage: `url(https://zero-one01.oss-cn-shenzhen.aliyuncs.com/app/ljxp.png)`, 
                       backgroundSize: 'contain', 
                       backgroundRepeat: 'no-repeat', 
                       backgroundPosition: 'center' }">
        </view>
      </view>
    </view>
  </s-layout>
</template>

<script>
export default {
  data() {
    return {
      currentTab: 'handmade',
      backgroundImage: 'https://zero-one01.oss-cn-shenzhen.aliyuncs.com/app/90b4a6667b55278d7835311a8d34715.png',
      finishedCues: [
        { id: 1, name: 'ZeroOne S1', imageUrl: 'https://zero-one01.oss-cn-shenzhen.aliyuncs.com/2025/04/187e45af90dee94208b507d7b17efdd62f%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20250418043534.jpg' },
          { id: 2, name: 'ZeroOne S2', imageUrl: 'https://zero-one01.oss-cn-shenzhen.aliyuncs.com/2025/04/187e45af90dee94208b507d7b17efdd62f%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20250418043534.jpg' },
          { id: 3, name: 'ZeroOne S1', imageUrl: 'https://zero-one01.oss-cn-shenzhen.aliyuncs.com/2025/04/187e45af90dee94208b507d7b17efdd62f%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20250418043534.jpg' },
          { id: 4, name: 'ZeroOne SSR', imageUrl: 'https://zero-one01.oss-cn-shenzhen.aliyuncs.com/2025/04/187e45af90dee94208b507d7b17efdd62f%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20250418043534.jpg' },
       ]
    };
  },

  methods: {
    handleTabChange(tab) {
      this.currentTab = tab;
    },
    initPage() {
      console.log('页面初始化完成');
    },
    handleBookTest() {
      uni.navigateTo({ url:'/pages/index/reservation' })
    },
    handleSelectMatch() {
      uni.navigateTo({ url:'/pages/index/selectMatch' })
    },
    handleCueClick(id) {
      uni.navigateTo({ url: `/pages/index/cueDetail?id=${id}` })
    },
    // 新增：查看更多按钮点击事件
    handleLoadMore() {
      console.log('更多成品杆');

      uni.navigateTo({ url:'/pages/index/cpCueList' })


    }
  },
  onLoad() {
    this.initPage();
  }
}
</script>

<style>
.s-layout-content {
  overflow: auto;
}

.home-container {
  position: relative;
  min-height: 100vh;
  background-size: cover; 
  background-repeat: no-repeat;
  background-position: center;
  padding-top: 130px;
  padding-bottom: 120px;
  box-sizing: border-box;
}

/* 导航栏样式 */
.center-nav {
  position: fixed;
  top: 70px;
  left: 0;
  right: 0;
  z-index: 100;
  height: 80px;
  display: flex;
  align-items: center;
}

.top-nav {
  display: flex;
  justify-content: center;
  max-width: 100%;
  width: 100%;
}

.nav-item-wrapper {
  flex: 1;
  max-width: 120px;
  height: 80px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.nav-item {
  padding: 15px 20px;
  cursor: pointer;
  text-align: center;
  white-space: nowrap;
  color: white;
  font-weight: bold;
  font-size: 34rpx;
  position: relative;
  z-index: 101;
}

.nav-item.active {
  border-bottom: 3rpx solid white;
}

/* 内容容器 */
.content-container {
  width: 100%;
  padding: 0 20rpx;
  box-sizing: border-box;
  margin-top: 20px;
}

/* 成品杆列表区域 */
.finished-cues-section {
  padding: 20rpx;
  margin-top: 0;
  display: flex;
  flex-direction: column;
  gap: 30rpx; /* 列表与按钮之间的间距 */
}

.cues-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20rpx;
}

.cue-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  background-color: rgba(0, 0, 0, 0.3);
  border-radius: 16rpx;
  padding: 20rpx;
  backdrop-filter: blur(5rpx);
  transition: transform 0.3s ease;
}

.cue-item:active {
  transform: scale(0.98);
}

.cue-image {
  width: 100%;
  height: 300rpx;
  object-fit: cover;
  border-radius: 10rpx;
  margin-bottom: 15rpx;
}

.cue-name {
  color: white;
  font-size: 28rpx;
  text-align: center;
  padding: 10rpx 0;
  font-weight: 500;
}

/* 新增：查看更多按钮样式 */
.load-more-btn {
  width: 100%;
  height: 80rpx;
  background-color: rgba(255, 255, 255, 0.1);
  border-radius: 10rpx;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 20rpx;
  cursor: pointer;
  transition: background-color 0.3s ease;
}

.load-more-btn:active {
  background-color: rgba(255, 255, 255, 0.2);
}

.btn-text {
  color: white;
  font-size: 30rpx;
  font-weight: 500;
}

/* 其他标签页内容 */
.other-content {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 600rpx;
  margin-top: 20rpx;
}

.placeholder-text {
  color: rgba(255, 255, 255, 0.7);
  font-size: 32rpx;
}

/* 底部固定按钮 */
.fixed-bottom-btn {
  position: fixed;
  bottom: 120px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  gap: 20px;
  padding: 0 20px;
  z-index: 100;
}

.custom-btn {
  width: 160px;
  height: 60px;
  border: none;
  background-color: transparent;
  padding: 0;
  margin: 0;
}

.custom-btn text {
  display: none;
}
</style>